#include "common.h"
#include"mainwidget.h"
#include"gamewidge.h"
#include<QWidget>
#include<QVBoxLayout>
#include<QIcon>
#include<QBrush>
#include<QLabel>
#include<QPushButton>
#include<QResizeEvent>
#include<QTimer>
#include<QPoint>
#include<QLineF>
#include<QMouseEvent>
#include<QGraphicsView>
#include<QGraphicsScene>

Common::Common()
{
    this->resize(1500,799);
    this->setWindowTitle("STAR WARS");
    this->setWindowIcon(QIcon("img/DS.png"));
    this->setBackgroundBrush(QBrush(QPixmap("img/BG1.png")));

    this->setMouseTracking(true);

    scence=new QGraphicsScene;
    scence->setSceneRect(0,0,this->width()-2,this->height()-2);
    this->setScene(scence);

    gun=new Qgun("img/pao",scence);
    gun->setPos(this->width()/2,this->height());
    scence->addItem(gun);

    fish1=new QFish("img/fish11.png",scence)；
    fish2=new QFish("img/fish22.png",scence);
    fish3=new QFish("img/fish33.png",scence);
    fish4=new QFish("img/fish44.png",scence);
    fish5=new QFish("img/fish55.png",scence);



    timer =new QTimer;
    connect(timer,SIGNAL(timeout()),scence,SLOT(advance()));
    timer->start(100);
}

void Common::resizeEvent(QResizeEvent *event)
{
    this->setBackgroundBrush(QBrush(QPixmap("img/BG1.png").scaled(event->size())));
}

void Common::mouseMoveEvent(QMouseEvent *event)
{
    QPoint p;
    p=event->pos();

    QLine line(this->width()/2,this->height(),p.x()+70,p.y());

    QLineF linef(line);
    gun->setRotation(-(linef.angle()-90));


}

void Common::mousePressEvent(QMouseEvent *event)
{
    QPoint p=event->pos();
    QLineF linef(this->width()/2,this->height(),p.x(),p.y());
    QBullet *bullet=new QBullet("img/B.png",scence,linef.angle());

}
